package com.xfcy.blog.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xfcy.blog.common.R;
import com.xfcy.blog.common.constant.Constant;
import com.xfcy.blog.common.constant.SqlConstant;
import com.xfcy.blog.entity.User;
import com.xfcy.blog.mapper.SystemConfigMapper;
import com.xfcy.blog.entity.SystemConfig;
import com.xfcy.blog.mapper.UserMapper;
import com.xfcy.blog.service.SystemConfigService;
import com.xfcy.blog.service.UserService;
import org.apache.tomcat.util.bcel.Const;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 系统配置表(SystemConfig)表服务实现类
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:06
 */
@Service("systemConfigService")
public class SystemConfigServiceImpl extends ServiceImpl<SystemConfigMapper, SystemConfig> implements SystemConfigService {

    /**
     * 查询系统配置
     * @return
     */
    @Override
    public R getConfig() {
        QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.last(SqlConstant.LIMIT_ONE);
        SystemConfig systemConfig = baseMapper.selectOne(queryWrapper);
        return R.success(systemConfig);
    }

    /**
     * 修改配置
     * @param systemConfig
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R updateConfig(SystemConfig systemConfig) {
        baseMapper.updateById(systemConfig);
        return R.success();
    }


    // 自定义方法 ============
    @Override
    public SystemConfig getCustomizeOne() {
        return baseMapper.selectOne(new QueryWrapper<SystemConfig>().last(SqlConstant.LIMIT_ONE));
    }

}


